package org.jradweb.core.orm;

import javax.persistence.Column;
import javax.persistence.Embeddable;

import org.hibernate.validator.Length;

/**
 * 
 * 
 * Created On 2008-4-23
 * 
 * @author <a href="mailto:wagzhi@gmail.com">Paul Wang</a>
 * @version $Id: MultiSiteKey.java 149 2008-10-10 03:10:10Z wagzhi $
 */
@Embeddable
public class MultiSiteKey implements java.io.Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = -2272197788550169412L;
	
	public MultiSiteKey(){}

	public MultiSiteKey(String id, Integer siteId) {
		this.id = id;
		this.siteId = siteId;
	}

	@Column(name = "id", columnDefinition = "UUID")
	@Length(max = 32)
	private String id;

	@Column(name = "site_id", columnDefinition = "siteId")
	private int siteId;

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public int getSiteId() {
		return siteId;
	}

	public void setSiteId(int siteId) {
		this.siteId = siteId;
	}

	@Override
	public boolean equals(Object obj) {
		if(obj==null||!MultiSiteKey.class.isInstance(obj))
			return false;
		
			MultiSiteKey key=(MultiSiteKey)obj;
			if(this.id==null&&key.getId()==null){
				if(this.siteId==key.siteId)
					return true;
				return false;
			}
			else if(this.id!=null&&key.getId()!=null){
				if(this.id.equals(key.getId())){
					if(this.siteId==key.siteId){
						return true;
					}
				}
			}
			return false;
	
	}

	@Override
	public String toString() {
		return id;
	}

}
